<template>
  <div class="form-card">
    <div class="form-title">
      <i class="fas fa-user form-icon"></i>
      <h2>基本信息</h2>
    </div>

    <form @submit.prevent="handleSubmit">
      <div class="form-group">
        <label for="name" class="form-label">
          <i class="fas fa-signature"></i>
          姓名 <span class="required">*</span>
        </label>
        <input 
          type="text" 
          class="form-control" 
          id="name" 
          v-model="formData.name" 
          required 
          placeholder="请输入您的姓名"
        >
      </div>

      <div class="form-group">
        <label for="idCard" class="form-label">
          <i class="fas fa-id-card"></i>
          身份证号 <span class="required">*</span>
        </label>
        <input 
          type="text" 
          class="form-control" 
          id="idCard" 
          v-model="formData.idCard" 
          required 
          placeholder="请输入18位身份证号码" 
          maxlength="18"
        >
      </div>

      <div class="form-group">
        <label for="phone" class="form-label">
          <i class="fas fa-mobile-alt"></i>
          手机号码 <span class="required">*</span>
        </label>
        <input 
          type="tel" 
          class="form-control" 
          id="phone" 
          v-model="formData.phone" 
          required 
          placeholder="请输入11位手机号码" 
          maxlength="11"
        >
      </div>

      <div class="form-buttons">
        <button type="button" class="btn btn-secondary" disabled>
          <i class="fas fa-arrow-left"></i>
          上一步
        </button>
        <button type="submit" class="btn btn-primary">
          下一步
          <i class="fas fa-arrow-right"></i>
        </button>
      </div>
    </form>
  </div>
</template>

<script setup>
import { reactive } from 'vue'

const props = defineProps({
  modelValue: {
    type: Object,
    required: true
  }
})

const emit = defineEmits(['update:modelValue', 'next'])

const formData = reactive({
  name: props.modelValue.name || '',
  idCard: props.modelValue.idCard || '',
  phone: props.modelValue.phone || ''
})

const handleSubmit = () => {
  // Emit updated form data to parent
  emit('update:modelValue', { ...props.modelValue, ...formData })
  
  // Validate and move to next step
  if (!formData.name.trim()) {
    alert('请输入姓名')
    return
  }
  if (!/^\d{18}$/.test(formData.idCard)) {
    alert('请输入有效的18位身份证号')
    return
  }
  if (!/^\d{11}$/.test(formData.phone)) {
    alert('请输入有效的11位手机号')
    return
  }
  
  emit('next')
}
</script>

<style scoped>
.form-card {
  background-color: white;
  border-radius: 16px;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
  padding: 30px;
  margin-bottom: 30px;
}

.form-title {
  display: flex;
  align-items: center;
  margin-bottom: 30px;
  border-bottom: 2px solid #f0f0f0;
  padding-bottom: 20px;
}

.form-icon {
  font-size: 32px;
  color: #3498db;
  margin-right: 15px;
}

.form-title h2 {
  font-size: 28px;
  font-weight: 700;
  color: #2980b9;
  margin: 0;
}

.form-group {
  margin-bottom: 25px;
}

.form-label {
  display: flex;
  align-items: center;
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 12px;
  color: #444;
}

.form-label i {
  margin-right: 10px;
  color: #3498db;
  width: 24px;
  text-align: center;
}

.form-control {
  width: 100%;
  padding: 16px 20px;
  font-size: 20px;
  border: 2px solid #ddd;
  border-radius: 10px;
  transition: all 0.3s;
}

.form-control:focus {
  border-color: #3498db;
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
  outline: none;
}

.form-control::placeholder {
  color: #aaa;
  font-size: 18px;
}

.form-buttons {
  display: flex;
  justify-content: space-between;
  margin-top: 40px;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 30px;
  font-size: 20px;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.3s;
  min-width: 160px;
}

.btn i {
  margin: 0 8px;
}

.btn-primary {
  background-color: #3498db;
  color: white;
}

.btn-primary:hover {
  background-color: #2980b9;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.btn-primary:disabled {
  background-color: #bdc3c7 !important;
  border-color: #bdc3c7 !important;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-secondary {
  background-color: #e0e0e0;
  color: #555;
}

.btn-secondary:hover {
  background-color: #d0d0d0;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.btn-secondary:disabled {
  background-color: #f0f0f0;
  color: #aaa;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.required {
  color: red;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .form-card {
    padding: 20px;
  }

  .form-title h2 {
    font-size: 24px;
  }

  .form-icon {
    font-size: 28px;
  }

  .form-label {
    font-size: 18px;
  }

  .form-control {
    font-size: 18px;
    padding: 14px 16px;
  }

  .btn {
    padding: 14px 20px;
    font-size: 18px;
    min-width: 120px;
  }

  .form-buttons {
    flex-direction: column;
    gap: 15px;
  }

  .form-buttons .btn {
    width: 100%;
  }
}
</style>